<template>
    <el-table
        :data="tableData"
        style="width: 100%"
        :height="curr_in == 1 ? oHeight : null"
        :class="curr_in==='1'?'active':''"
        :show-header="showHeader"
        :default-expand-all="false"
        :row-class-name="getRowClassName"
        :cell-style="cellStyle"
        :header-cell-style="cellStyle"
    >
        <el-table-column type="expand" :key="'Serial'+curr_in">
            <template slot-scope="scope">
                <slot :row="scope.row"></slot>
                <!-- <edit-power ></edit-power> -->
                <edit-power
                    v-if="scope.row.data"
                    :tableData="scope.row.data"
                    :showHeader="false"
                    class="second_level"
                    v-on="$listeners"
                    :curr_in="parseInt(curr_in)+1"
                ></edit-power>
                <!-- <edit-power v-if="scope.row.data&&scope.row.data.length>0" :tableData="scope.row.data" :showHeader="false" :hideSlot="true"@addNext="addNext" @powerDelete="powerDelete" @powerEdit="powerEdit" @showCheckBox="showCheckBox" @sortInput="sortInput"@pNameInput="pNameInput" curr_in="4"></edit-power>-->
            </template>
        </el-table-column>
        <!-- 当前级别 -->
        <!-- <el-table-column label="级别" width="80" key="pSort">
            <template slot-scope="scope" >
                {{curr_in}}
            </template>
        </el-table-column>-->
        <!-- 三级权限空格 -->
        <!-- <el-table-column v-else-if="hideSlot" width="50">
        </el-table-column>-->
        <el-table-column label="排序" width="80" :key="'pSort'+curr_in">
            <template slot-scope="scope">
                <el-input
                    class="input_box_sort"
                    v-model="scope.row.pSort"
                    @blur="sortInput(scope.row)"
                ></el-input>
            </template>
        </el-table-column>
        <el-table-column label="名称" min-width="180" :key="'pName'+curr_in">
            <template slot-scope="scope">
                <div class="power_name_box">
                    <el-input
                        class="input_box_name"
                        v-model="scope.row.pName"
                        @blur="pNameInput(scope.row)"
                    ></el-input>
                    <div class="new_add_next" v-if="curr_in < 4" @click="addNext(scope.$index, scope.row)">
                        <span>+</span>
                        <p>新增下级</p>
                    </div>
                </div>
            </template>
        </el-table-column>
        <el-table-column label="是否展示标识new" width="140" :key="'isNew'+curr_in">
            <template slot-scope="scope">
                <el-checkbox
                    v-model="scope.row.is_new"
                    true-label="1"
                    false-label="0"
                    @change="isNew(scope.row)"
                ></el-checkbox>
            </template>
        </el-table-column>
        <el-table-column label="是否首页显示" width="140" :key="'isHomeShow'+curr_in">
            <template slot-scope="scope">
                <el-checkbox
                    v-model="scope.row.home_show"
                    true-label="1"
                    false-label="0"
                    @change="isHomeShow(scope.row)"
                ></el-checkbox>
            </template>
        </el-table-column>
        <el-table-column label="是否选中菜单" width="140" :key="'pSet'+curr_in">
            <template slot-scope="scope">
                <el-checkbox
                    v-model="scope.row.pSet"
                    true-label="1"
                    false-label="0"
                    @change="showCheckBox(scope.row)"
                ></el-checkbox>
            </template>
        </el-table-column>
        <el-table-column label="操作" width="180" :key="'operation'+curr_in">
            <template slot-scope="scope">
                <el-button type="primary" size="mini" @click="powerEdit(scope.$index, scope.row)">编辑</el-button>
                <el-button
                    size="mini"
                    type="danger"
                    @click="powerDelete(scope.$index, scope.row)"
                >删除</el-button>
            </template>
        </el-table-column>
    </el-table>
</template>
<script>
import { resize } from "@/common/js/height.js";
export default {
	name:"edit-power",
    data() {
        return {
            oHeight: 600
        };
    },
    props: ["tableData", "showHeader", "hideSlot", "curr_in"],
    methods: {
        cellStyle() {
            return { "text-align": "center" };
        },
        sortInput(row) {
            this.$emit("sort-input", row);
        },
        pNameInput(row) {
            this.$emit("p-name-input", row);
        },
        showCheckBox(val) {
            this.$emit("show-check-box", val);
        },
        isHomeShow(val) {
            this.$emit("is-home-show", val);
        },
        isNew(val) {
            this.$emit("is-new", val);
        },
        powerEdit(index, row) {
            this.$emit("power-edit", row, this.curr_in, index);
        },
        powerDelete(index, row) {
            this.$emit("power-delete", row.pId, this.curr_in, index);
        },
        getRowClassName({ row, rowIndex }) {
            if (!(row.data && row.data.length > 0)) {
                return "row-expand-cover";
            }
        },
        addNext(index, row) {
            this.$emit("add-next", row.pId, this.curr_in, index);
        }
    },
	mounted() {
		resize(this)
	}
};
</script>
<style lang="scss" scoped>
/deep/table {
    width: auto !important;
    min-width: 100%;
}
.el-table /deep/ {
    border: 1px solid #ebeef5;
    border-bottom: none;
    // .el-table {
    //     border-top: none;
    // }
    .el-table__expanded-cell[class*="cell"] {
        padding: 0;
        border-bottom: 0;
    }
    .is-scrolling-none {
        overflow: auto;
    }
    .el-table {
        border: 0;
        .el-table__expand-column {
            padding-left: 50px;
        }
        .el-table .el-table__expand-column{
            padding-left: 80px;
        }
        .el-table .el-table .el-table__expand-column{
            padding-left: 110px;
        }
        .el-table .el-table .el-table .el-table__expand-column{
            padding-left: 140px;
        }
    }
}
.el-table.active {
    border-width: 1px;
}
/deep/.input_box_sort .el-input__inner {
    width: 60px;
    height: 30px;
    text-align: center;
    box-sizing: border-box;
    // padding: 0;
}
/deep/.input_box_name .el-input__inner {
    width: 100px;
    height: 30px;
    text-align: center;
}
/deep/.row-expand-cover .el-table__expand-icon {
    visibility: hidden;
}
.power_name_box {
    display: flex;
    align-items: center;
}
.power_name_box .input_box_name.el-input {
    width: auto;
}
.new_add_next {
    display: flex;
    align-items: center;
    margin-left: 20px;
    color: #19b0df;
}
.new_add_next > span {
    width: 22px;
    height: 22px;
    background: #19b0df;
    color: #fff;
    text-align: center;
    line-height: 19px;
    font-size: 22px;
    border-radius: 5px;
}
.new_add_next > p {
    margin-left: 10px;
}
</style>